package com.example.sprinbgbatch.itemreader;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.item.ItemReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.List;

//@Configuration
public class ItemReaderDemo {
    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    //创建任务对象
    @Bean
    public Job myItemReaderDemoJob(){
        return jobBuilderFactory.get("myItemReaderDemoJob")
                .start(myItemReaderDemoStep())
                .build();
    }

    @Bean
    public Step myItemReaderDemoStep() {
        return stepBuilderFactory.get("myItemReaderDemoStep")
                .<String,String>chunk(2)
                .reader(itemReaderRead())
                .writer(list -> {
                    for (String item : list
                         ) {
                        System.out.println("####>" + item);
                    }
                }).build();
    }

    @Bean
    public MyItemReader itemReaderRead() {
        List<String> data = Arrays.asList("张三","李四","王五","赵六","洪七");
        return new MyItemReader(data);
    }


}
